<template>
  <div class="main">
    <div class="title">
      <div class="titleBlock"></div>
      <div class="titleText">新增项目信息</div>
    </div>
    <div class="card1">
      <div class="card1Title">新增项目信息</div>
      <div class="card1Section">
        <div class="form1">
          <el-form
            ref="ruleFormRef"
            :model="ruleForm"
            :rules="rules"
            label-width="120px"
            class="demo-ruleForm"
            :size="formSize"
          >
            <el-form-item label="项目ID" prop="projectID">
              <el-input v-model="ruleForm.projectID" placeholder="请输入内容" />
            </el-form-item>
            <el-form-item label="项目名称" prop="projectName">
              <el-input
                v-model="ruleForm.projectName"
                placeholder="请输入内容"
              />
            </el-form-item>
            <el-form-item label="所属套餐" prop="packageName">
              <el-select v-model="ruleForm.packageName" placeholder="请选择">
                <el-option
                  v-for="item in medicalName"
                  :label="item.packageName"
                  :value="item.medicalID"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="项目价格" prop="projectPrice">
              <el-input v-model="ruleForm.projectPrice" />
            </el-form-item>
            <el-form-item label="项目介绍" prop="projectIntroduction">
              <el-input
                v-model="ruleForm.projectIntroduction"
                type="textarea"
                :rows="5"
              />
            </el-form-item>
            <el-form-item label="注意事项" prop="announcements2">
              <el-input
                v-model="ruleForm.announcements2"
                type="textarea"
                :rows="5"
              />
            </el-form-item>
            <el-form-item label="项目状态" prop="projectStatus">
              <el-switch
                v-model="ruleForm.projectStatus"
                active-text="使用中"
                inactive-text="未使用"
                active-value="true"
                inactive-value="false"
              >
              </el-switch>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="add">保存</el-button>
              <el-button @click="cancel">取消</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { ref, reactive, toRefs, computed, watch } from "vue";
import { useRouter } from "vue-router";
import {
  getMedicalName,
  addPhysicalExaminationProject,
} from "../../utils/api/tiJian";
export default {
  props: {},
  setup() {
    const data = reactive({
      ruleForm: {
        projectID: "",
        projectName: "",
        packageName: "",
        projectPrice: "",
        projectIntroduction: "",
        announcements2: "",
        projectStatus: "true",
      },
      medicalName: [],
    });
    getMedicalName().then((dataName) => {
      console.log(dataName);
      if (dataName.data.code == 200) {
        data.medicalName = dataName.data.data;
      }
    });
    const router = useRouter();
    const add = () => {
      addPhysicalExaminationProject(data.ruleForm).then((addData) => {
        console.log(addData);
        if (addData.data.code == 200) {
          ElMessage({
            message: "添加成功",
            type: "success",
          });
          router.push({
            path: "/home/hospitalInfoManage/physicalExaminationProject",
          });
        }
      });
    };
    const cancel = () => {
      router.push({
        path: "/home/hospitalInfoManage/physicalExaminationProject",
      });
    };
    return { ...toRefs(data), add, cancel };
  },
};
</script>
<style lang="scss" scoped>
.title {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 0 0 30px;
  box-sizing: border-box;
  .titleBlock {
    width: 50px;
    height: 13px;
    background-color: #006eff;
    border-radius: 20px;
  }
  .titleText {
    font-size: 30px;
    margin-left: 20px;
  }
}
.card1 {
  box-shadow: 1px 1px 5px 1px rgba(194, 188, 188, 0.486);
  width: 100%;
  margin-bottom: 30px;
  .card1Title {
    padding: 20px;
    box-sizing: border-box;
    color: #006eff;
    background-color: #f2f2f2;
  }
  .card1Section {
    width: 100%;
    background-color: white;
    padding: 40px 0;
    box-sizing: border-box;
    .form1 {
      width: 40%;
    }
  }
}
</style>